﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace TrailMapManager.Common.Converters
{
    public class DistanceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (double.IsNaN((double)value))
            {
                value = 0.0;
            }
            double distance = (double)value;
            if (distance < 100.0)
            {
                return Math.Round(distance, 0) + "m";
            }
            else if (distance > 100.0 && distance < 10000.0)
            {
                return Math.Round(distance / 1000, 2).ToString() + "km";
            }
            else
            {
                return Math.Round(distance / 1000, 1).ToString() + "km";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
